FROM python:3.13.0-alpine AS installer

RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
RUN apk add --no-cache bash gcc python3-dev musl-dev linux-headers sudo

WORKDIR /opt/neutron/neutron

RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
COPY requirements.txt .
RUN pip install -r requirements.txt

FROM python:3.13.0-alpine

LABEL name="neutronpanel"
LABEL vendor="neutronpanel"
LABEL maintainer="cxykevin"
LABEL version="0.0.0"
LABEL description="Neutron Panel"

WORKDIR /opt/neutron/neutron

# 安装依赖
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
RUN apk add --no-cache openssh-server openssh bash sudo
RUN pip uninstall pip -y

# 配置ssh
RUN echo "Port 22" >> /etc/ssh/sshd_config
RUN echo "AddressFamily any" >> /etc/ssh/sshd_config
RUN echo "ListenAddress 0.0.0.0" >> /etc/ssh/sshd_config
RUN echo "HostKey /etc/ssh/ssh_host_rsa_key" >> /etc/ssh/sshd_config
RUN echo "HostKey /etc/ssh/ssh_host_ecdsa_key" >> /etc/ssh/sshd_config
RUN echo "HostKey /etc/ssh/ssh_host_ed25519_key" >> /etc/ssh/sshd_config
RUN echo "" > /etc/motd
RUN ssh-keygen -A
RUN /usr/sbin/sshd

# 配置代码
COPY --from=installer /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages

COPY . .

# 清理体积
RUN rm -rf /var/cache/apk/*
RUN rm requirements.txt

# 配置启动命令
RUN echo "/usr/sbin/sshd" >> /start.sh
RUN echo "cd /opt/neutron/neutron" >> /start.sh
RUN echo "python main.py" >> /start.sh

# 基本信息
EXPOSE 1231

CMD ["bash", "/start.sh"]